package com.mundoa3.screen;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.math.collision.BoundingBox;
import com.mundoa3.Assets;
import com.mundoa3.SpaceWarsGame;

public class MenuScreen implements Screen {

	SpaceWarsGame game;
	
	OrthographicCamera cam;
	SpriteBatch batcher;
	
	BoundingBox startBounds;

	Vector3 touchPoint;
	
	public MenuScreen(SpaceWarsGame game){
		this.game = game;
		cam = new OrthographicCamera(7, 9);
		cam.position.set(7f/2 ,9f/2, 0);
		batcher = new SpriteBatch();
		
		startBounds = new BoundingBox(new Vector3(2,2,0), new Vector3(5,3,0));
		
		touchPoint = new Vector3();
	}
	@Override
	public void dispose() {
		batcher.dispose();
		
	}

	@Override
	public void hide() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void render(float arg0) {
		
		if (Gdx.input.justTouched()){
			cam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
			
			if (startBounds.contains(touchPoint)){
				game.setGame();
				return;
			}
		}
		
		
		GL10 gl = Gdx.graphics.getGL10();
		gl.glClearColor(0,0,0,1);
		gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		
		cam.update();
		batcher.setProjectionMatrix(cam.combined);
		
		batcher.disableBlending();
		
		batcher.begin();
		batcher.draw(Assets.background, 0, 0, 7, 9);
		batcher.end();
		
		batcher.enableBlending();
		batcher.begin();
		batcher.draw(Assets.title, 1, 4, 5, 4);
		batcher.draw(Assets.start, 2, 2, 3, 1);
		batcher.end();
	}

	@Override
	public void resize(int width, int height) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void show() {
		// TODO Auto-generated method stub
		
	}

}
